
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        2/7/2009
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteCustomerResponseDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteCustomerResponseDAL
    {
        #region  Properties
		 
		public static string FIELD_CUSTOMERRESPONSEID = "CustomerResponseId";  
		public static string FIELD_CUSTOMERNAME = "CustomerName";  
		public static string FIELD_CUSTOMEREMAIL = "CustomerEmail";  
		public static string FIELD_CONTENT = "Content";  
		public static string FIELD_JOB = "Job";  
		public static string FIELD_ADDRESS = "Address";  
		public static string FIELD_PHONENUMBER = "PhoneNumber";  
		public static string FIELD_DESCRIPTION = "Description"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteCustomerResponse
        /// </summary>
        /// <param name="CustomerResponseId">Primary Keys</param>
        /// <returns>Collection of websiteCustomerResponseInfo</returns>
        public static websiteCustomerResponseInfo SelectOne(int CustomerResponseId)
        {
            websiteCustomerResponseInfo _websiteCustomerResponseInfo = new websiteCustomerResponseInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteCustomerResponseSelectOne", CustomerResponseId);
                if (dr.Read())
                    setwebsiteCustomerResponseInfo(dr, ref _websiteCustomerResponseInfo);
                return _websiteCustomerResponseInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteCustomerResponse
        /// </summary>
        /// <returns>Collection of websiteCustomerResponseInfo</returns>
        public static List<websiteCustomerResponseInfo> SelectAll()
        {
            List<websiteCustomerResponseInfo> lstwebsiteCustomerResponse = new List<websiteCustomerResponseInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteCustomerResponseSelectAll");
                setListwebsiteCustomerResponseInfo(ref dr, ref lstwebsiteCustomerResponse);
                return lstwebsiteCustomerResponse;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteCustomerResponsenfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteCustomerResponseInfo</returns>
        public static List<websiteCustomerResponseInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteCustomerResponseInfo> lstwebsiteCustomerResponse = new List<websiteCustomerResponseInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteCustomerResponseSelectByFilters");
                setListwebsiteCustomerResponseInfo(ref dr, ref lstwebsiteCustomerResponse);
                return lstwebsiteCustomerResponse;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteCustomerResponse
        /// </summary>
        /// <param name="websiteCustomerResponseInfo">Entity of websiteCustomerResponse</param>
        /// <returns>error code</returns>
        public static int Insert(websiteCustomerResponseInfo _websiteCustomerResponseInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteCustomerResponseInsert" 
											, _websiteCustomerResponseInfo.CustomerName
											, _websiteCustomerResponseInfo.CustomerEmail
											, _websiteCustomerResponseInfo.Content
											, _websiteCustomerResponseInfo.Job
											, _websiteCustomerResponseInfo.Address
											, _websiteCustomerResponseInfo.PhoneNumber
											, _websiteCustomerResponseInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteCustomerResponse
        /// </summary>
        /// <param name="websiteCustomerResponseInfo">Entity of websiteCustomerResponse</param>
        /// <returns>error code</returns>
        public static int Update(websiteCustomerResponseInfo _websiteCustomerResponseInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteCustomerResponseUpdate"
											, _websiteCustomerResponseInfo.CustomerResponseId
											, _websiteCustomerResponseInfo.CustomerName
											, _websiteCustomerResponseInfo.CustomerEmail
											, _websiteCustomerResponseInfo.Content
											, _websiteCustomerResponseInfo.Job
											, _websiteCustomerResponseInfo.Address
											, _websiteCustomerResponseInfo.PhoneNumber
											, _websiteCustomerResponseInfo.Description
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="CustomerResponseId">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int CustomerResponseId)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteCustomerResponseDelete", CustomerResponseId);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteCustomerResponseInfo(ref SqlDataReader dr, ref List<websiteCustomerResponseInfo> lstwebsiteCustomerResponse)
        {
            websiteCustomerResponseInfo _websiteCustomerResponseInfo = null;
            while (dr.Read())
            {
                _websiteCustomerResponseInfo = new websiteCustomerResponseInfo();
                setwebsiteCustomerResponseInfo(dr, ref _websiteCustomerResponseInfo);
                lstwebsiteCustomerResponse.Add(_websiteCustomerResponseInfo);
            }
        }

        private static void setwebsiteCustomerResponseInfo(SqlDataReader dr, ref websiteCustomerResponseInfo _websiteCustomerResponseInfo)
        {
			_websiteCustomerResponseInfo.CustomerResponseId = dr[websiteCustomerResponseDAL.FIELD_CUSTOMERRESPONSEID] != DBNull.Value ? Convert.ToInt32(dr[websiteCustomerResponseDAL.FIELD_CUSTOMERRESPONSEID]) : 0;
			_websiteCustomerResponseInfo.CustomerName = dr[websiteCustomerResponseDAL.FIELD_CUSTOMERNAME] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_CUSTOMERNAME]) : string.Empty;
			_websiteCustomerResponseInfo.CustomerEmail = dr[websiteCustomerResponseDAL.FIELD_CUSTOMEREMAIL] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_CUSTOMEREMAIL]) : string.Empty;
			_websiteCustomerResponseInfo.Content = dr[websiteCustomerResponseDAL.FIELD_CONTENT] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_CONTENT]) : string.Empty;
			_websiteCustomerResponseInfo.Job = dr[websiteCustomerResponseDAL.FIELD_JOB] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_JOB]) : string.Empty;
			_websiteCustomerResponseInfo.Address = dr[websiteCustomerResponseDAL.FIELD_ADDRESS] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_ADDRESS]) : string.Empty;
			_websiteCustomerResponseInfo.PhoneNumber = dr[websiteCustomerResponseDAL.FIELD_PHONENUMBER] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_PHONENUMBER]) : string.Empty;
			_websiteCustomerResponseInfo.Description = dr[websiteCustomerResponseDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteCustomerResponseDAL.FIELD_DESCRIPTION]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteCustomerResponse]";

        #endregion
    }
}

		